//
//  SceneryView.m
//  Lovelife
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SceneryView.h"
#import "UIImageView+WebCache.h"
#import "SceneryDetailsController.h"
#import "NightManager.h"
#define Width self.frame.size.width
#define textWidthLeft self.frame.size.width / 20
#define textWidth self.frame.size.width / 20 * 19
@implementation SceneryView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.inferface = [[UIScrollView alloc]init];
        
        UITapGestureRecognizer *photoCut = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoC)];
        
        self.photoView = [[UIImageView alloc]init];
        [_inferface addSubview:_photoView];
        [_phoneLabel release];
        _photoView.userInteractionEnabled = YES;
        [_photoView addGestureRecognizer:photoCut];
        [photoCut release];
        
        self.nameLabel = [[BaseLabel alloc]init];
        self.nameLabel.font = [UIFont systemFontOfSize:24];
        [_inferface addSubview:_nameLabel];
        [_nameLabel release];
        
        self.englishLabel = [[BaseLabel alloc]init];
        [_inferface addSubview:_englishLabel];
        [_englishLabel release];
        
        self.introTiLabel = [[BaseLabel alloc]init];
        self.introTiLabel.font = [UIFont systemFontOfSize:20];
        _introTiLabel.text = @"简介";

        [_inferface addSubview:_introTiLabel];
        [_introTiLabel release];
        
        UITapGestureRecognizer *tapcut = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cut:)];
        
        
#pragma 加个手势
        self.introductionLabel = [[BaseLabel alloc]init];
        self.introductionLabel.tag = 1001;
        [_inferface addSubview:_introductionLabel];
        _introductionLabel.numberOfLines = 0;
        [_introductionLabel release];
        _introductionLabel.userInteractionEnabled = YES;
        [_introductionLabel addGestureRecognizer:tapcut];
        [tapcut release];
        
        self.addLabel = [[BaseLabel alloc]init];
        _addLabel.text = @"地址";
        self.addLabel.font = [UIFont systemFontOfSize:20];
        [_inferface addSubview:_addLabel];
        [_addLabel release];
        
        self.addressLabel = [[BaseLabel alloc]init];
        self.addressLabel.numberOfLines = 0;
        [_inferface addSubview:_addressLabel];
        [_addressLabel release];
        
        UITapGestureRecognizer *waytoTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cutw:)];
        self.waytoTLabel = [[BaseLabel alloc]init];
        _waytoTLabel.text = @"路线";
        self.waytoTLabel.font = [UIFont systemFontOfSize:20];
        [_inferface addSubview:_waytoTLabel];
        [_waytoTLabel release];
        
        self.waytoLabel = [[BaseLabel alloc]init];
        self.waytoLabel.numberOfLines = 0;
        [_inferface addSubview:_waytoLabel];
        self.waytoLabel.userInteractionEnabled = YES;
        [self.waytoLabel addGestureRecognizer:waytoTap];
        [_waytoLabel release];
        
        self.phoneTitleLabel = [[BaseLabel alloc]init];
        _phoneTitleLabel.text = @"电话";
        self.phoneTitleLabel.font = [UIFont systemFontOfSize:20];
        [_inferface addSubview:_phoneTitleLabel];
        [_phoneTitleLabel release];
        
        self.phoneLabel = [[BaseLabel alloc]init];
        [_inferface addSubview:_phoneLabel];
        [_phoneLabel release];
        
        self.timeTiileLabel = [[BaseLabel alloc]init];
        _timeTiileLabel.text = @"时间";
        self.timeTiileLabel.font = [UIFont systemFontOfSize:20];
        [_inferface addSubview:_timeTiileLabel];
        [_timeTiileLabel release];
        
        self.timesLabel = [[BaseLabel alloc]init];
        [_inferface addSubview:_timesLabel];
        [_timesLabel release];
        
        self.httpLabel = [[BaseLabel alloc]init];
        _httpLabel.text = @"网址";
        self.httpLabel.font = [UIFont systemFontOfSize:20];
        [_inferface addSubview:_httpLabel];
        [_httpLabel release];
        
        self.qyelurlLabel = [[BaseLabel alloc]init];
        [_inferface addSubview:_qyelurlLabel];
        _qyelurlLabel.numberOfLines = 0;
        [_qyelurlLabel release];

        self.priceTitle = [[BaseLabel alloc]init];
        _priceTitle.text = @"票价";
        [_inferface addSubview:_priceTitle];
        [_priceTitle release];
#pragma 加个手势
        UITapGestureRecognizer *tt = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cutx:)];
        
        self.priceLabel = [[BaseLabel alloc]init];
        [_inferface addSubview:_priceLabel];
        self.priceLabel.tag = 1002;
        [_priceLabel release];
        _priceLabel.userInteractionEnabled = YES;
        [_priceLabel addGestureRecognizer:tt];
        
        [self addSubview:_inferface];
        [_inferface release];
    }
    return self;
}

- (void)cut:(UITapGestureRecognizer *)sender
{
    NSString *cutStr = self.model.introduction;
    
    [self.delegate pageCut:cutStr];
}

- (void)cutx:(UITapGestureRecognizer *)sender
{
    NSString *cutStr = self.model.price;
    [self.delegate pageCut:cutStr];
}

- (void)cutw:(UITapGestureRecognizer *)sender
{
    NSString *cutStr = self.model.wayto;
    [self.delegate pageCut:cutStr];
}


- (void)photoC
{
    [self.delegateSen photoShow];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.inferface.frame = self.frame;
    self.photoView.frame = CGRectMake(0, 0, Width, 160);
    
    self.nameLabel.frame = CGRectMake(0, 160, Width / 2, 30);
    
    
    
    self.englishLabel.frame = CGRectMake(textWidthLeft, 190, textWidth, 30);
    
    self.introTiLabel.frame = CGRectMake(textWidthLeft, 220, textWidth, 23);
    
    self.introductionLabel.frame = CGRectMake(0, 243, Width, 83);
    
    self.addLabel.frame = CGRectMake(textWidthLeft, 326, textWidth, 30);
    
    self.addressLabel.frame = CGRectMake(0, 356, Width, 50);
    
    self.waytoTLabel.frame = CGRectMake(textWidthLeft, 406, textWidth, 30);
    
    self.waytoLabel.frame = CGRectMake(0, 436, Width, 50);
    
    self.phoneTitleLabel.frame = CGRectMake(textWidthLeft, 486, textWidth, 30);
    
    self.phoneLabel.frame = CGRectMake(0, 516, Width, 50);
    
    self.timeTiileLabel.frame = CGRectMake(textWidthLeft, 566, textWidth, 30);
    
    self.timesLabel.frame = CGRectMake(0, 596, Width, 50);
    
    self.httpLabel.frame = CGRectMake(textWidthLeft, 646, textWidth, 30);
    
    self.qyelurlLabel.frame = CGRectMake(0, 676, Width, 50);
    
    self.priceTitle.frame = CGRectMake(textWidthLeft, 726, textWidth, 30);
    
    self.priceLabel.frame = CGRectMake(0, 736, Width, 100);
    
    _inferface.contentSize = CGSizeMake(Width, 903);
}

- (void)setvalueScenry
{
    NSString *yingji = @"对不起,崭时没有此信息";
    NSURL *strUrl = [NSURL URLWithString:self.model.photo];
    [self.photoView sd_setImageWithURL:strUrl];
    self.nameLabel.text = self.model.chinesename;
    self.englishLabel.text = self.model.englishname;
    self.introductionLabel.text = self.model.introduction;
    self.addressLabel.text = self.model.address;
    self.waytoLabel.text = self.model.wayto;
    if ([self.model.phone isEqualToString:@""]) {
        self.phoneLabel.text = yingji;
    }else{
        NSString *phoneStr = [NSString stringWithFormat:@"%@", self.model.phone];
        self.phoneLabel.text = phoneStr;
    }
    
    if ([self.model.times isEqualToString:@"0"]) {
        self.timesLabel.text = yingji;
    }else{
        self.timesLabel.text = self.model.times;
    }
    
    if (self.model.price.length == 0) {
        self.priceLabel.text = yingji;
    }else{
        self.priceLabel.text = self.model.price;
    }
    
    self.qyelurlLabel.text = self.model.qyerurl;
    self.priceLabel.text = self.model.price;
    
}

- (void)dealloc
{
    [_inferface release];
    [_photoView release];
    [_nameLabel release];
    [_englishLabel release];
    [_introTiLabel release];
    [_introductionLabel release];
    [_addLabel release];
    [_addressLabel release];
    [_waytoTLabel release];
    [_waytoLabel release];
    [_phoneTitleLabel release];
    [_phoneLabel release];
    [_timeTiileLabel release];
    [_timesLabel release];
    [_httpLabel release];
    [_qyelurlLabel release];
    [_priceTitle release];
    [_priceLabel release];
    [super dealloc];
}

- (void)setNightDayModel
{
    [NightManager setLabelColorWithLabel:self.nameLabel];
    [NightManager setLabelColorWithLabel:self.englishLabel];
    [NightManager setLabelColorWithLabel:self.introductionLabel];
    [NightManager setLabelColorWithLabel:self.addLabel];
    [NightManager setLabelColorWithLabel:self.addressLabel];
    [NightManager setLabelColorWithLabel:self.waytoTLabel];
    [NightManager setLabelColorWithLabel:self.waytoLabel];
    [NightManager setLabelColorWithLabel:self.phoneTitleLabel];
    [NightManager setLabelColorWithLabel:self.phoneLabel];
    [NightManager setLabelColorWithLabel:self.timeTiileLabel];
    [NightManager setLabelColorWithLabel:self.timesLabel];
    [NightManager setLabelColorWithLabel:self.httpLabel];
    [NightManager setBackgroundColorWithView:self];
    [NightManager setBackgroundColorWithView:self.inferface];
    [NightManager setLabelColorWithLabel:self.qyelurlLabel];
    [NightManager setLabelColorWithLabel:self.priceTitle];
    [NightManager setLabelColorWithLabel:self.priceLabel];
}


@end
